

clear all 
use the_dataset.dta

keep if  standard == 1

keep culture1 culture2 culture_d  unemp culture1 case_1 case_2 CCAA1 ///
educ_basic1-educ_sup1 age051-age661 income1 income2 income_d NMIEMB1 size_dummy1-size_dummy5 number_spanish1 ccaadummy1-ccaadummy17 ANOENC1 yeardummy1-yeardummy9

global covariates1 culture1 educ_basic1-educ_sup1 age051-age661 income1 NMIEMB1 size_dummy1-size_dummy5 number_spanish1 ccaadummy1-ccaadummy17

preserve

drop if case_2 != 1

* use seed 1, 2, or 3 for different iterations
set seed 1
* gen placebo treatments
forvalues i=1(1)2001{

gen ind_culture`i' = _n 
gen aux`i' = rnormal(0,1) 
sort aux`i'
gen placebo`i' = 1 in 1/529
replace placebo`i' = 0 if placebo`i'!=1 
sort ind_culture`i'
drop ind_culture`i' aux`i'
}
*


gen est1 = 0 
gen se1 = 0

forvalues i=1(1)2000{

teffects nnmatch (culture_d $covariates1) (placebo`i') , ematch(ANOENC1) nneighbor(3) atet biasadj($covariates1)
matrix maest_`i' = e(b)
scalar scest_`i' = maest_`i'[1,1]

matrix mase_`i' = e(V)
scalar scse_`i' = sqrt(mase_`i'[1,1])

replace est2 = scest_`i' in `i'
replace se2  = scse_`i' in `i'

drop placebo`i' 
save placebo_match_2_2.dta, replace
}
scalar drop _all

gen t_estat_2 = est2/se2 

gen false_pos_10_2 = 1 if t_estat_2<= -1.64 | t_estat_2>=1.64
replace false_pos_10_2 = 0 if t_estat_2> -1.64 & t_estat_2<1.64

gen false_pos_5_2 = 1 if t_estat_2<= -1.96 | t_estat_2>=1.96
replace false_pos_5_2 = 0 if t_estat_2> -1.96 & t_estat_2<1.96

gen cont = _n

sum false_pos_5_2 false_pos_10_2 if cont<2001
